<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.Map"%>
<%@page import="it.unibz.ti2.internetPizzeria.entities.Pizza"%>
<html>
<head>
<title>Internet pizzeria - New order</title>
<%
	Map<Pizza, Integer> pizzasMap = (Map<Pizza, Integer>)(request.getAttribute("pizzasMap"));
	Map<Drink, Integer> drinksMap = (Map<Drink, Integer>)(request.getAttribute("drinksMap"));
%>
	<script type="text/javascript">
		function load(){

<%			for (Map.Entry<Pizza, Integer> entry : pizzasMap.entrySet()) {
%>
				var price = <%out.print(entry.getKey().getPrice());%>;
				var price2 = <%out.print(entry.getKey().getPrice()*entry.getValue().intValue());%>;

				document.getElementById("tablePizzaTdI<%out.print(entry.getKey().getId());%>").innerHTML = price.toFixed(2);
				document.getElementById("tablePizzaTdII<%out.print(entry.getKey().getId());%>").innerHTML = price2.toFixed(2);
<%			}
			for (Map.Entry<Drink, Integer> entry : drinksMap.entrySet()) {
%>
				var price = <%out.print(entry.getKey().getPrice());%>;
				var price2 = <%out.print(entry.getKey().getPrice()*entry.getValue().intValue());%>;
				
				document.getElementById("tableDrinkTdI<%out.print(entry.getKey().getId());%>").innerHTML = price.toFixed(2);
				document.getElementById("tableDrinkTdII<%out.print(entry.getKey().getId());%>").innerHTML = price2.toFixed(2);
<%			}
%>

		var price1 = <%out.print(request.getAttribute("productsPrice").toString());%>;
		var price2 = <%out.print(request.getAttribute("deliveryPrice").toString());%>;
		var price3 = <%out.print(request.getAttribute("sumPrice").toString());%>;
		document.getElementById("tableSumTd").innerHTML = 
			"Price: <b>"+price1.toFixed(2)+"</b><br /> Delivery fee: <b>"+price2.toFixed(2)+"</b><br /><hr />To pay: <b>"+price3.toFixed(2)+"</b><br />";		
		}	
	</script>



</head>
<body onload="load()">	
<%@ include file="navigationMenu.jsp" %>
	<h3>Order information</h3>
	<h4>You ordered package which will contain:</h4>
	<table>
	<tr>
			<th colspan="6" bgcolor="EEEEEE">Ordered products</th>
	</tr>
	<tr>
			<th width="100" bgcolor="EEEEEE">Product number</td>
			<th width="100" bgcolor="DDDDDD">Product name</td>
			<th width="200" bgcolor="EEEEEE">Product description</td>
			<th width="100" bgcolor="DDDDDD">Product price</td>
			<th width="100" bgcolor="EEEEEE">Amount of product</td>
			<th width="130" bgcolor="DDDDDD">Price</td>
	</tr>
	<%
		for (Map.Entry<Pizza, Integer> entry : pizzasMap.entrySet()) {
	%>
			<tr>
				<td align="center" bgcolor="EEEEEE"><%out.print(entry.getKey().getId());%></td>
				<td bgcolor="DDDDDD"><%out.print(entry.getKey().getName());%></td>
				<td bgcolor="EEEEEE"><%out.print(entry.getKey().getDescription());%></td>
				<td id="tablePizzaTdI<%out.print(entry.getKey().getId());%>" align="right" bgcolor="DDDDDD"><%out.print(entry.getKey().getPrice());%></td>
				<td align="right" bgcolor="EEEEEE"><%out.print(entry.getValue().intValue());%></td>
				<td id="tablePizzaTdII<%out.print(entry.getKey().getId());%>" align="right" bgcolor="DDDDDD">
				<%out.print(entry.getKey().getPrice()*entry.getValue().intValue());%>
				</td>
			</tr>
	<%		}
		for (Map.Entry<Drink, Integer> entry : drinksMap.entrySet()) {
	%>
			<tr>
				<td align="center" bgcolor="EEEEEE"><%out.print(entry.getKey().getId());%></td>
				<td bgcolor="DDDDDD"><%out.print(entry.getKey().getName());%></td>
				<td bgcolor="EEEEEE"><%out.print(entry.getKey().getDescription());%></td>
				<td id="tableDrinkTdI<%out.print(entry.getKey().getId());%>" align="right" bgcolor="DDDDDD"><%out.print(entry.getKey().getPrice());%></td>
				<td align="right" bgcolor="EEEEEE"><%out.print(entry.getValue().intValue());%></td>
				<td id="tableDrinkTdII<%out.print(entry.getKey().getId());%>" align="right" bgcolor="DDDDDD">
				<%out.print(entry.getKey().getPrice()*entry.getValue().intValue());%>
				</td>
			</tr>
	<%		}
	%>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td id="tableSumTd" align="right" bgcolor="DDDDDD"></td>
			</tr>
	</table>
	<h4>Package will be delivered to address</h4>
	  <table>
	   <tr>
		<td>name:</td>
		<td><%out.print(request.getAttribute("name"));%></td>
	   </tr>
	   <tr>	
		<td>surname:</td>
		<td><%out.print(request.getAttribute("surname"));%></td>
	   </tr>
	   <tr>
		<td>city:</td>
		<td><%out.print(request.getAttribute("city"));%></td>
	   </tr>
	   <tr>
		<td>street and number:</td>
		<td><%out.print(request.getAttribute("streetAndNumber"));%></td>
	   </tr>
	   <tr>
		<td>country:</td>
		<td><%out.print(request.getAttribute("country"));%></td>
	   </tr>
	   <tr>
		<td>zip code:</td>
		<td><%out.print(request.getAttribute("zipCode"));%></td>
	   </tr>
	  </table>	
	<h4>To check your order status go to <a href="checkOrderStatus">Check order status</a> page</h4>
</body>
</html>
